// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';
//设置默认的请地址
//本地环境

// 动态判断环境
const isDev = process.env.NODE_ENV === 'development';

// 根据环境切换 baseURL
const baseURL = isDev
  ? 'http://localhost:8000/api'  // 开发环境走 proxy.ts
  : 'https://api.bi.d-wormhole.com/api'; // ✅ 生产环境固定地址

/** 获取当前的用户 GET /api/currentUser */
// export async function currentUser(options?: { [key: string]: any }) {
//   return request<{
//     data: API.CurrentUser;
//   }>('/api/currentUser', {
//     method: 'GET',
//     ...(options || {}),
//   });
// }

/** 退出登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/api/login/outLogin', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 登录接口 POST /api/login/account */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  return request<API.LoginResult>(`${baseURL}/login`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body
  });
}


/** 获取销售订单数据统计 */
export async function sale_overview_statistc(
  params: {
    // query
    /** 页面的容量 */
    _method?: string;
    page_size?: string;
    page?: string;
    status?: string;
    tag?: string;
    begin_billdate?: string;
    end_billdate?: string;
    receiver_type?: string;
    receiver_id?: string;
    receiver_category?: string;
    type?: string;
    area_lv_1?: string;
    area_lv_2?: string;
    turnover_store_id?: string;
    group_by?: string;


  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    sum:{
      count?:number,
      quantity?:number,
      stockout_quantity?:number,
      stockout_progress?:number,
    }
    // 其他可能的字段...
  }>(`${baseURL}/docs_statistic/sale_overview_statistic`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}
// //获取销售订单明细统计
// export async function getNotices(options?: { [key: string]: any }) {
//   return request<API.NoticeIconList>('/api/notices', {
//     method: 'GET',
//     ...(options || {}),
//   });
// }

/** 获取规则列表 GET /api/rule */
export async function sale_statistc(
  params: {
    // query
    /** 页面的容量 */
    _method?: string;
    page_size?: string;
    page?: string;
    status?: string;
    tag?: string;
    begin_billdate?: string;
    end_billdate?: string;
    receiver_type?: string;
    receiver_id?: string;
    receiver_category?: string;
    type?: string;
    area_lv_1?: string;
    area_lv_2?: string;
    turnover_store_id?: string;
    group_by?: string;


  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    // 其他可能的字段...
  }>(`${baseURL}/docs_statistic/sale_statistic`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

/** 获取规则列表 GET /api/rule */
export async function dispatch_statistc(
  params: {
    // query
    /** 页面的容量 */
    _method?: string;
    page_size?: string;
    page?: string;
    status?: string;
    tag?: string;
    begin_billdate?: string;
    end_billdate?: string;
    receiver_type?: string;
    receiver_id?: string;
    receiver_category?: string;
    origin_order_type?: string;
    area_lv_1?: string;
    area_lv_2?: string;
    turnover_store_id?: string;
    group_by?: string;
  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    // 其他可能的字段...
  }>(`${baseURL}/docs_statistic/dispatch_statistic`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

//获取销售退货统计
export async function sale_return_statistc(
  params: {
    // query
    /** 页面的容量 */
    _method?: string;
    page_size?: string;
    page?: string;
    status?: string;
    tag?: string;
    begin_billdate?: string;
    end_billdate?: string;
    deliver_type?: string;
    deliver_id?: string;
    // receiver_category?: string;
    type?: string;
    area_lv_1?: string;
    area_lv_2?: string;
    turnover_store_id?: string;
    group_by?: string;


  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    // 其他可能的字段...
  }>(`${baseURL}/docs_statistic/sale_return_statistic`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

/** 获取规则列表 GET /api/rule */
export async function tags(
  params: {
    // query
    status?: string;

  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    // 其他可能的字段...
  }>(`${baseURL}/basic/tags`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

/** 获取规则列表 GET /api/rule */
export async function product_attribute_group(
  params: {
    // query
    status?: string;

  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];
    // 其他可能的字段...
  }>(`${baseURL}/basic/product_attribute_group`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

/** 获取规则列表 GET /api/rule */
export async function staff_config(
  params: {
    // query
    status?: string;

  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: {
      setting?: {
        sale?: {
          id?: string;
        },
        selfBuildReturn?: {
          id?: string;
        },
        invoiceReview?: {
          id?: string;
        }
        ;
      };
    };  // 明确返回数据结构包含data字段
    // 其他可能的字段...
  }>(`${baseURL}/basic/staff_config`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

/** 获取规则列表 GET /api/rule */
export async function export_config(
  params: {
    // query
    type?: string;
    mode?: string;

  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: {
      list?:any[]
    };  // 明确返回数据结构包含data字段
    // 其他可能的字段...
  }>(`${baseURL}/basic/export_config`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

/** 获取规则列表 GET /api/rule */
export async function sales_categories(
  params: {
    // query
    status?: string;

  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    // 其他可能的字段...
  }>(`${baseURL}/basic/sales_categories`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

/** 获取规则列表 GET /api/rule */
export async function sale_return_categories(
  params: {
    // query
    status?: string;

  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    // 其他可能的字段...
  }>(`${baseURL}/basic/sale_return_categories`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

export async function distributors(
  params: {
    // query
    status?: string;

  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    // 其他可能的字段...
  }>(`${baseURL}/basic/distributors`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

export async function distributor_stores(
  params: {
    // query
    status?: string;
    distributor_id?: string;

  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    // 其他可能的字段...
  }>(`${baseURL}/basic/distributor_stores`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

export async function distributor_area(
  params: {
    // query
    status?: string;

  },
  options?: { [key: string]: any },
) {
  const userInfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const token = userInfo.token|| '';
  return request<{
    data: any[];  // 明确返回数据结构包含data字段
    total: number;
    // 其他可能的字段...
  }>(`${baseURL}/basic/distributor_area`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'token': token
    },
    params: {
      ...params,
      ...(options || {}),
    }
  });
}

